package com.ruoyi.web.controller.client;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.interceptor.LoginUser;
import com.ruoyi.framework.interceptor.MpAuthorize;
import com.ruoyi.system.domain.SysProduct;
import com.ruoyi.web.dto.client.WorkOrderSubmit;
import com.ruoyi.web.dto.consumer.UpdatePassword;
import com.ruoyi.web.service.consumer.MpConsumerService;
import com.ruoyi.web.service.consumer.MpWorkOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

@Api(tags = "用户端登录/注册")
@RestController
@RequestMapping("/client/work-order")
public class SysWorkOrderController {

    @Autowired
    private MpWorkOrderService workOrderService;

    @ApiOperation(value = "提交工单", notes = "用户在h5页面提交工单", response = Boolean.class)
    @MpAuthorize
    @PostMapping("submit")
    public AjaxResult submit(@RequestBody @Valid WorkOrderSubmit workOrderSubmit,
                                @LoginUser Long userId) throws Exception {
        return AjaxResult.success(workOrderService.submit(workOrderSubmit, userId));
    }

    @ApiOperation(value = "工单列表", notes = "h5显示工单的列表信息", response = Boolean.class)
    @MpAuthorize
    @GetMapping("/list")
    public TableDataInfo getList(@RequestParam(name = "keyword", required = false) String keyword,
                              @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                              @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                              @LoginUser Long userId) {
        return workOrderService.getList(keyword, pageNum, pageSize, userId);
    }

    @ApiOperation(value = "获取详情", notes = "获取详情", response = Boolean.class)
    @MpAuthorize
    @GetMapping("/detail")
    public AjaxResult detail(@RequestParam(name = "id") Integer id,
                                 @LoginUser Long userId) {
        return AjaxResult.success( workOrderService.detail(id, userId));
    }

}
